/*
 * @Date: 2021-09-08 09:49:26
 * @Author: Acckno1
 * @LastEditTime: 2021-09-08 10:32:27
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1e4 + 10;

int n;
int inorder[N], postorder[N];
// int l[N], r[N];
unordered_map<int, int> l, r;

vector<int> ans;

int build(int u, int s, int e) {
	if (s > e) return -1;
	int i = s;
	// 定位根在中序的位置;
	while (i < e && postorder[u] != inorder[i]) i ++;
	// 访问当前处理的树的根
    l[inorder[i]] = build(u - (e - i) - 1, s, i - 1); // 递归处理左子树
    r[inorder[i]] = build(u - 1, i + 1, e); // 递归处理右子树
	return inorder[i];
}

void BFS(int u) {
    bool is_right = false;
    deque<int> dq;
    dq.push_back(u);
    is_right = true;
    ans.push_back(u);
    while (dq.size()) {
        int n = dq.size();
        for (int i = 0; i < n; i ++ ) {
            if (is_right) {
                int head = dq.front(); dq.pop_front();
                if (l.count(head) && l[head] != -1) dq.push_back(l[head]), ans.push_back(l[head]);
                if (r.count(head) && r[head] != -1) dq.push_back(r[head]), ans.push_back(r[head]);
            } else {
                int head = dq.back(); dq.pop_back();
                if (r.count(head) && r[head] != -1) dq.push_front(r[head]), ans.push_back(r[head]);
                if (l.count(head) && l[head] != -1) dq.push_front(l[head]), ans.push_back(l[head]);
            }
        }
        is_right = !is_right;
    }
}


// 这里默认了 每个节点的数据很小 如果每个节点的数据很大的话 需要用哈希表离散化处理数据
// 或是用链表存储 树
inline void solution() {
    // mm(l, -1);
    // mm(r, -1);
    cin >> n;
    for (int i = 0; i < n; i ++ ) cin >> inorder[i];
    for (int i = 0; i < n; i ++ ) cin >> postorder[i];

    BFS(build(n - 1, 0, n - 1));
    
    cout << ans[0];
    for (int i = 1; i < (int)ans.size(); i ++ ) cout << " " << ans[i];
    cout << endl;
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}